const { promisify } = require("util");
const fs = require("fs");
const rename = promisify(fs.rename);
exports.uploadImg = async (req,res)=>{
    console.log(req.file);
//     // {
//   fieldname: 'file',
//   originalname: 'xxmLogo.png',
//   encoding: '7bit',
//   mimetype: 'image/png',
//   destination: 'public/uploads',
//   filename: 'e21697aceb9b392e02f9ae956ea9c78a',
//   path: 'public\\uploads\\e21697aceb9b392e02f9ae956ea9c78a',
//   size: 25335
// }
let uploadArr = req.file.originalname.split(".");
let uploadType = uploadArr[uploadArr.length - 1];
try {
    await  rename(
        "./public/uploads/" + req.file.filename,
        "./public/uploads/" + req.file.filename + "." + uploadType
      );
    res.status(200).json({
        code:200,
        message:'上传成功',
        data:'http://localhost:3000/uploads/'+req.file.filename+'.'+uploadType
    })
} catch (error) {
    res.status(500).json({
        code:500,
        message:'上传失败',
        data:error
    })
}
}